import { IStack } from "./IStark";

class ArrayStark<T> implements IStack<T> {
  private data: T[] = [];
  constructor(data?: T[]) {
    this.data = data || [];
  }

  push(item: T) {
    this.data.push(item);
  }
  pop() {
    return this.data.pop();
  }
  toString() {
    return String(this.data);
  }
  size() {
    return this.data.length;
  }
  isEmpty() {
    return this.data.length === 0;
  }
  peek() {
    return this.data[this.data.length - 1];
  }
}

const stark1 = new ArrayStark<number>();

stark1.push(1);
console.log(stark1.toString());
stark1.push(2);
console.log(stark1.toString());
stark1.push(3);
console.log(stark1.toString());
stark1.push(4);
console.log(stark1.toString());
stark1.pop();
console.log(stark1.toString());
stark1.pop();
console.log(stark1.toString());
stark1.pop();
console.log(stark1.toString());

console.log("-----------------------------");

export { ArrayStark };
